from django.db import models
from django.contrib.auth.models import AbstractUser

class UserProfile(AbstractUser):
    name = models.CharField(max_length=200, blank=True,verbose_name='姓名')
    email = models.EmailField(max_length=200, blank=True,verbose_name='邮箱')
    phone = models.CharField(max_length=200, blank=True,verbose_name='电话')
    unit = models.OneToOneField('Unit', on_delete=models.DO_NOTHING, null=True, blank=True,verbose_name='所属单位')
    created_at = models.DateTimeField(auto_now_add=True,verbose_name='创建时间')
    updated_at = models.DateTimeField(auto_now=True,verbose_name='更新时间')

    def __str__(self):
        return self.username
    
    class Meta:
        verbose_name = '用户'
        verbose_name_plural = verbose_name


class Unit(models.Model):
    name = models.CharField(max_length=200, verbose_name='单位名称')
    description = models.CharField(max_length=200, blank=True,verbose_name='单位描述')
    created_at = models.DateTimeField(auto_now_add=True,verbose_name='创建时间')
    updated_at = models.DateTimeField(auto_now=True,verbose_name='更新时间')

    def __str__(self):
        return self.name
    
    class Meta:
        verbose_name = '单位管理'
        verbose_name_plural = verbose_name
        ordering = ['updated_at']